package cn.getech.data.development.service;

import cn.getech.data.development.entity.ConfConnect;
import cn.getech.data.development.entity.vo.ConfConnectDetail;
import cn.getech.data.development.model.dto.ConfConnectDto;
import cn.getech.data.development.model.qo.ConfConnectQO;
import cn.getech.data.development.model.req.confconnect.TableInfoFieldRelationReq;
import cn.getech.data.development.model.req.confconnect.TableInfoFieldReq;
import cn.getech.data.development.model.res.confconnect.TableInfoFieldRelationRes;
import cn.getech.data.development.model.res.confconnect.TableInfoFieldRes;
import cn.getech.data.development.model.vo.UserCreaterVO;
import cn.getech.data.intelligence.common.utils.BaseRes;
import cn.getech.data.intelligence.common.utils.PageUtils;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 配置连接表 服务类
 * </p>
 *
 * @author zenith
 * @since 2018-08-22
 */
public interface ConfConnectService extends IService<ConfConnect> {
    /**
     * 测试所有连接，并设置连接状态
     */
    void testAllConnect(Integer typeId, boolean isDebug) throws InterruptedException;

    BaseRes testConnect(ConfConnect confConnect, boolean isDecryptPwd, boolean isDebug);

    BaseRes testConnect(ConfConnect confConnect, boolean isDecryptPwd);

    PageUtils queryPage(Map<String, Object> params);

    ConfConnect selectOne(Integer   dbType);
    boolean checkIfRef(Integer id);
    boolean checkExistByName(String name, Integer create_per, ConfConnect confConnect);
    boolean checkPermission(Integer id);
    boolean checkExistById(Integer id);
    PageUtils selectListPage(Map<String, Object> params);
    PageUtils listNoRelation(Map<String, Object> params);
    JSONArray getDatabaseNameToTableName(ConfConnect confConnect) ;
    PageUtils pageByNameAndProId(Map<String, Object> params) ;
    List<ConfConnect> selectByNameAndProId(Map<String, Object> params) ;

    /**
    * @Description 根据类型和工程id查询对应的数据源信息
    * @Author  hujz
    * @Date   2019/8/24 15:05
    * @Param  confConnectQO 查询条件
    * @Return List<ConfConnectDto>
    * @Exception
    *
    */
    List<ConfConnectDto> listByCondition(ConfConnectQO confConnectQO);

    /**
    * @Description 验证是否有启用的任务，在使用这个连接。如果有，则不能删除
    * @Author  hujz
    * @Date   2019/9/10 10:52
    * @Param  id:连接id  type:类型（删除：1 编辑：2）
    * @Return
    * @Exception
    *
    */
    void checkAnalysisInfoUsed(Integer id, Integer type);



    /**
     * @Description 查询所有的kafka类型的连接数据
     * @Author  hujz
     * @Date   2019/9/17 10:52
     *
     * @param procId
     */
    List<ConfConnectDto> listAllKafka(Integer procId);

    List<ConfConnect> selectQuery(Integer userId);

    List<ConfConnect> selectQuery2(Integer userId);

    /**
     * 根据角色信息查询数据的权限信息
     */
    PageUtils listPageByRole(Map<String, Object> params);

    List<Map<Integer,String>> userList();

    /**
     * 根据租户信息查询数据的权限信息
     */
    PageUtils listPageByTenant(Map<String, Object> params);

    ConfConnectDetail getDetail(Long id);

    void cronTimeDate();

    void enableOrDisable(Long id);

    List<String> getDbnames(ConfConnect confConnect);

    List<TableInfoFieldRes> getTableInfoField(TableInfoFieldReq req);


    TableInfoFieldRelationRes getTableInfoField(TableInfoFieldRelationReq req);

    void updateCollectionTaskDbName(Integer sourceId, String dbName);

    List<UserCreaterVO>  selectCreaterList();


    List<String> getMetaDbNames(Integer id);


    boolean checkAdminPermission(Integer id, Integer operation);


    List<Integer> queryIdsByProjectId(Integer projectId);

    Integer selectByName(String name);
}
